home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / program / getusage.asm < prev    next >
Assembly Source File  |  2000-02-28  |  3KB  |  150 lines

  1. ; Directory Opus 4
  2. ; Original GPL release version 4.12
  3. ; Copyright 1993-2000 Jonathan Potter
  4. ; This program is free software; you can redistribute it and/or
  5. ; modify it under the terms of the GNU General Public License
  6. ; as published by the Free Software Foundation; either version 2
  7. ; of the License, or (at your option) any later version.
  8. ; This program is distributed in the hope that it will be useful,
  9. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ; GNU General Public License for more details.
  12. ; You should have received a copy of the GNU General Public License
  13. ; along with this program; if not, write to the Free Software
  14. ; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  15. ; All users of Directory Opus 4 (including versions distributed
  16. ; under the GPL) are entitled to upgrade to the latest version of
  17. ; Directory Opus version 5 at a reduced price. Please see
  18. ; http://www.gpsoft.com.au for more information.
  19. ; The release of Directory Opus 4 under the GPL in NO WAY affects
  20. ; the existing commercial status of Directory Opus 5.
  21.  
  22. * Get CPU usage as a percentage
  23. * getusage() routine takes no arguments, returns value from 0 to 100 in d0
  24. * basically pinched from an old version of xoper, thanks Werner :)
  25.  
  26.     XDEF _getusage
  27.  
  28.     section code
  29.  
  30. _getusage:
  31.     movem.l d1-d3/a6,-(sp)
  32.     move.l 4,a6
  33.     move.l 280(a6),d0
  34.     move.l 284(a6),d1
  35.     move.l oldidl,d3
  36.     move.l d0,oldidl
  37.     sub.l d3,d0
  38.     move.l olddisp,d3
  39.     move.l d1,olddisp
  40.     sub.l d1,d3
  41.     move.l d0,d1
  42.     sub.l d3,d1
  43.     sub.l d3,d0
  44.     neg.l d3
  45.     bsr getpcent
  46.     movem.l (sp)+,d1-d3/a6
  47.     rts
  48.  
  49. getpcent:
  50.     lsl.l #1,d3
  51.     move.l d3,d1
  52.     lsl.l #2,d3
  53.     add.l d1,d3
  54.     lsl.l #2,d3
  55.     move.l d3,d1
  56.     lsl.l #3,d3
  57.     move.l d3,d2
  58.     lsl.l #1,d3
  59.     add.l d2,d3
  60.     add.l d1,d3
  61.     move.l d0,d1
  62.     move.l d3,d0
  63.     bsr div32
  64.     rts
  65.  
  66. * 32-bit division routines
  67.  
  68. div32:
  69.     tst.l d1
  70.     beq div8
  71.     swap d1
  72.     move.w d1,d2
  73.     bne.s div1
  74.     swap d0
  75.     swap d1
  76.     swap d2
  77.     move.w d0,d2
  78.     beq.s div2
  79.     divu d1,d2
  80.     move.w d2,d0
  81. div2
  82.     swap d0
  83.     move.w d0,d2
  84.     divu d1,d2
  85.     move.w d2,d0
  86.     swap d2
  87.     move.w d2,d1
  88.     bra div8
  89. div1
  90.     moveq #$10,d3
  91.     cmpi.w #$80,d1
  92.     bcc.s div3
  93.     rol.l #8,d1
  94.     subq.w #8,d3
  95. div3
  96.     cmpi.w #$800,d1
  97.     bcc.s div4
  98.     rol.l #4,d1
  99.     subq.w #4,d3
  100. div4
  101.     cmpi.w #$2000,d1
  102.     bcc.s div5
  103.     rol.l #2,d1
  104.     subq.w #2,d3
  105. div5
  106.     tst.w d1
  107.     bmi.s div6
  108.     rol.l #1,d1
  109.     subq.w #1,d3
  110. div6
  111.     move.w d0,d2
  112.     lsr.l d3,d0
  113.     swap d2
  114.     clr.w d2
  115.     lsr.l d3,d2
  116.     swap d3
  117.     divu d1,d0
  118.     move.w d0,d3
  119.     move.w d2,d0
  120.     move.w d3,d2
  121.     swap d1
  122.     mulu d1,d2
  123.     sub.l d2,d0
  124.     bcc.s div7
  125.     subq.w #1,d3
  126.     add.l d1,d0
  127. div7
  128.     moveq #0,d1
  129.     move.w d3,d1
  130.     swap d3
  131.     rol.l d3,d0
  132.     swap d0
  133.     exg d1,d0
  134. div8
  135.     rts
  136.  
  137.     section data
  138.  
  139. oldidl
  140.     dc.l 0
  141. olddisp
  142.     dc.l 0
  143.  
  144.     end
  145.